<?php
class Shop_ManufacturerController extends Promotor_Controller_Action_Scaffold {

	public $skin = array(
		// forsuje domyslny template i style na admin
		'template' => 'admin',
		'style' => 'default',
		// layout
		'layout' => 'admin_shop',
		// rozszerzam konfiguracje
		'config' => array(
			'filename' => 'backend_config.ini'
		),
		'display' => array(
			'personalized' => true,
			'layout' => 'shop_manufacturer_display'
		)
	);

	public $acl = array(
		'list' => 'list',
		'add' => 'create',
		'edit' => 'update',
		'delete' => 'delete',
	
		'display' => 'show'
	);

	/**
	 * @see Promotor_Controller_Action_Scaffold specialization
	 */
	protected $_modelClass = 'Shop_Model_Manufacturer';
	protected $_formAddClass = 'Shop_Form_Manufacturer_Add';
	protected $_formEditClass = 'Shop_Form_Manufacturer_Edit';
	protected $_formRemoveClass = 'Shop_Form_Manufacturer_Remove';
	// end of specialization
	
	/**
	 * @return void
	 */
	public function indexAction() {
		$this->_forward('list');
	}
	
	/**
	 * Wyświetlanie kategorii i produktów
	 * @return void
	 */
	public function displayAction() {
		$config = $this->_helper->config('config.ini');

		$model = new Shop_Model_Manufacturer();

		/* @var $rq Zend_Controller_Request_Http */
		$rq = $this->getRequest();

		$alias = $rq->getParam('alias', $rq->getParam('id'));
		$this->view->alias = $alias;

		if (is_numeric($alias)) {
			$row = $model->findByIdCache($alias);
		} elseif (is_string($alias)) {
			$row = $model->findByAliasCache($alias);
		} else {
			$row = null;
		}

			if (null === $row) {
				/* @var $renderer Zend_Controller_Action_Helper_ViewRenderer */
				$renderer = $this->_helper->getHelper('ViewRenderer');
				$renderer->render('display.error');
				return;
			}

		$this->view->row = $row;
		
			$page   = $rq->getParam('page', 1);
			$onPage = $config->paginator->onPage;

			$model = new Shop_Model_Product();
			list($rowset, $select) = $model->findAllForManufacturerCache($row, $page, $onPage);

		$this->view->rowset = $rowset;

			$paginator = Zend_Paginator::factory($select);
			$paginator->setCurrentPageNumber($page);
			$paginator->setItemCountPerPage($onPage);

		$this->view->paginator = $paginator;
	}
}